package application;

import java.util.List;

import javax.swing.ImageIcon;

import technicalservices.error.ErrorDialog;
import technicalservices.error.ErrorHandler;

import domain.advertisement.AccountBalance;
import domain.advertisement.Ad;
import domain.advertisement.AdvertisementScheme;
import domain.advertisement.AdDatabase;
import domain.users.User;

public class AdController {
	
	private AdDatabase adDatabase;
	private AccountBalance balance;
	
	public AdController() {
		adDatabase = new AdDatabase();
		balance = new AccountBalance();
	}

	/** Handle Account Balance 
	 * @param user **/
	public double getFounds(User advertiser) {
		return balance.getFounds(adDatabase, advertiser);
	}
	
	/**
	 * This method adds an amount.
	 * If the amount is less than 0, and error will be displayed.
	 * @param amount
	 */
	public void addAmount(double amount) {
		if(0 > amount) 
			ErrorHandler.getInstance().showError("Can't add negative amount");
		balance.setAmount(amount);		
	}
	

	/** Handle advertisment **/
	/**
	 * This method retreives all Advertisments belonging to a
	 * specific Advertiser (user)
	 * @param advertiser
	 * @return List<Ad>
	 */
	public List<Ad> getAd(User advertiser) {
		return adDatabase.getAds(advertiser);
	}
	
	/**
	 * This method adds a new Advertisment
	 * @param advertiser, image, description, scheme
	 */

	public void addAd(User advertiser, ImageIcon image, String description, AdvertisementScheme scheme) {
		adDatabase.addAd(advertiser, image, description, scheme);
	}
	
	public void editAd(Ad ad, int index) {
		adDatabase.editAd(ad, index);
	}
	
	/**
	 * This method removes an Advertisment
	 * @param index
	 */
	public void removeAd(int index) {
		adDatabase.removeAd(index);	
	}

	public List<Ad> getAds() {
		return adDatabase.getAds();
	}
	
	public void printAds() {
		adDatabase.printAds();
	}

	public int getNumAds() {
		return adDatabase.getNumAds();
	}
}
